package list

import (
//"fmt"
)

//定义定list
type Object interface {
}
type List struct {
	values []Object
}

func New() List {
	var alist List = List{[]Object{}}
	return alist
}
func (al *List) Get(i int) (value Object) {
	if i < 0 || i > al.Size() {
		return nil
	}
	return al.values[i]
}
func (al *List) Add(value Object) {
	al.values = append(al.values, value)
}
func (al *List) Size() int {
	return len(al.values)
}
func (al *List) Values() []Object {
	return al.values
}
func (al *List) Remove(i int) {
	if i < 0 || i > al.Size() {
		return
	}
	if i == 0 {
		al.values = al.values[1:]
	} else if i == al.Size() {
		al.values = al.values[:i-1]
	} else {
		beforeAl := al.values[:i]
		laterAl := al.values[i+1:]
		newAl := []Object{}
		newAl = append(newAl, beforeAl...)
		newAl = append(newAl, laterAl...)
		al.values = newAl
	}
}
